package borge.web.teamspirit.client.widgets;


import borge.web.teamspirit.client.data.News;
import borge.web.teamspirit.client.interfaces.WidgetEventHandler;

import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class ShowNewsWidget extends BaseWidget {

	private VerticalPanel iPanel;
	private FlexTable iFlexTable;
	
	public ShowNewsWidget(WidgetEventHandler weh, News news, int numNews){
		super(weh);
		
		// table that looks like
		// title
		// date, time, author
		// text
		iFlexTable = new FlexTable();
		int row = 0;
		
		// Not sure about labels here..we want to create news in a richtexteditor,
		// which means we probably have to store html in string?
		
		Label title = new Label();
		Label dateAuthor = new Label();
		Label text = new Label();
		
		title.setText(news.getTitle());
		title.addStyleName("NewsTitle");
		
		// Calendar not supported by GWT
		String date = (news.getDate().getYear()+1900) + "-" + (news.getDate().getMonth()+1) + "-" + news.getDate().getDate();
		//dateAuthor.setText(date + " by " + news.getPoster().toString());
		dateAuthor.addStyleName("NewsDateAuthor");
		
		text.setText(news.getText());
		text.addStyleName("NewsText");
		
		iFlexTable.setWidget(row++, 0, title);
		iFlexTable.setWidget(row++, 0, dateAuthor);
		iFlexTable.setWidget(row++, 0, text);
		
		iPanel = new VerticalPanel();
		iPanel.add(iFlexTable);
		
		initWidget(iPanel);
	}
	
}
